package com.mylove.judas.yaya.ui.fragment.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.mylove.judas.yaya.R;
import com.mylove.judas.yaya.mvp.presenter.BaseView;


/**
 * Created by Administrator on 2017/5/12 0012.
 */
public abstract class BaseFragment<T> extends Fragment implements BaseView {

    protected Context mContext;
    private View view;
    private LinearLayout ll_content;

    protected T presenter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        mContext = getActivity();

        view = inflater.inflate(R.layout.fragment_base, container, false);

        ll_content = (LinearLayout) view.findViewById(R.id.ll_content);

        setContentView(getLayoutId());

        initView();

        setListener();

        return view;
    }

    public abstract void show();

    /**
     * 获取资源ID
     * @return
     */
    public abstract int getLayoutId();

    public void setContentView(@LayoutRes int layoutResID) {
        setContentView(View.inflate(mContext, layoutResID, null));
    }

    public void setContentView(View view) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        ll_content.addView(view, params);
    }

    public void initView(){

    }

    public void setListener(){

    }

    public View findViewById(@IdRes int id) {
        return ll_content.findViewById(id);
    }

    public void showToast(String msg){
        Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
    }


    @Override
    public void showNoData() {
//        showToast("showNoData()");
    }

    @Override
    public void showLoading() {
        showToast("showLoading()");
    }

    @Override
    public void dismissLoading() {
        showToast("dismissLoading()");
    }
}
